package descentFly.away3D4.element.Extends
{
	import descentFly.away3D4.element.df_element;
	import descentFly.chips.df_weapont;
	import descentFly.data.df_fields;
	
	import space.sp_utils;
	
	public class df_ammoController extends df_distanceController {
		
		public static const DEFAULT_COUNT: int = 10;
		
		public function df_ammoController(a_ctrl:df_element, a_options:Object) {
			sp_utils.checkParam(a_options, df_fields.FIELD_COUNT, DEFAULT_COUNT);
			super(a_ctrl, a_options);
		}
		
		override protected function doNearest():void {
			if (options[df_fields.FIELD_WEAPONTID]) {
				var weapont: df_weapont = myChip.weapontFromID(options[df_fields.FIELD_WEAPONTID]);
				
				if (weapont.limited) {
					var add: int = options[df_fields.FIELD_COUNT];
					if (weapont.options[df_weapont.FIELD_AMMOLIMIT] < weapont.ammo + add)
						add = weapont.options[df_weapont.FIELD_AMMOLIMIT] - weapont.ammo;
					if (add > 0) {
						if (weapont.ammo == 0) 
							myChip.currentWeapont = weapont;
						weapont.ammo += add;
						ctrl.pickUp();
					}
				}				
				super.doNearest();
			}
		}		
	}
}